package com.mimiwang.user.util;

import java.util.Random;

/**
 * @AUTHOR:游李滨
 * @DATE:2023/4/28 13:11
 */
public class RandomCodeUtil {

    public static String generateRandomCode(int length){
        StringBuilder sb = new StringBuilder();

        Random random = new Random();
        //自动生成验证码
        for (int i = 0; i < length; i++) {
            int num = random.nextInt(36);
            if( num > 25) {
                //生成数字
                sb.append(num-26);
            } else {
                //生成字母
                sb.append((char)('a'+ num));
            }

        }
        return sb.toString();
    }

    public static void main(String[] args) {
        System.out.println(generateRandomCode(6));
    }
}
